﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace HostAssistantCore
{
    class IISAdoHelper
    {
        #region 判断数据库中的站点数据是否存在
        /// <summary>
        /// 判断数据库中的站点数据是否存在
        /// </summary>
        /// <returns></returns>
        public static bool getSitesState()
        {
            bool flag = true;
            string sql = "  select * from sites where   1=1   ";
            Sites Sites = new Sites();
            var list = Data<Sites>.GetInstance().GetModelList(sql, Sites);
            if (list == null || list.Count == 0)//数据为空
            {
                flag = false;
            }
            return flag;
        }
        #endregion

        #region 从数据库表中获取站点信息
        /// <summary>
        /// 从数据库表中获取站点信息
        /// </summary>
        public static List<Sites> adoGetSitesInfo()
        {
            IISManager iismanager = new IISManager();
             
            if (!IISAdoHelper.getSitesState())
            {

                // 获取本地站点信息
                  
                List<string> sitelist = iismanager.getSiteInfo();
                foreach (string siteinfo in sitelist)
                {

                    NLogger.Fatal("siteinfo:"+ siteinfo);
                    string[] site = Regex.Split(siteinfo, "-@-");

                    //  存储到数据库

                    string insert_sql = "insert into sites(sid,sname,sbindings,sphysicalpath,screatetime,slogpath,susername,spassword, smaxbands, smaxconnections, scpulimit, smemeory, snetversion, stype, sstate, sphpath, shomepages) values(@sid,@sname,@sbindings,@sphysicalpath,@screatetime,@slogpath,@susername,@spassword, @smaxbands, @smaxconnections, @scpulimit, @smemeory, @snetversion, @stype, @sstate, @sphpath, @shomepages)";

                    string[] field = { "sid", "sname", "sbindings", "sphysicalpath", "screatetime", "slogpath", "susername", "spassword", "smaxbands", "smaxconnections", "scpulimit", "smemeory", "snetversion", "stype", "sstate", "sphpath", "shomepages" };
                    string[] values = site;
                    Sites s = new Sites();
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (field[i] == "sid")
                            s.sid = values[i];



                        else if (field[i] == "shomepages")
                            s.shomepages = values[i];

                        else if (field[i] == "sphpath")
                            s.sphpath = values[i];

                        else if (field[i] == "sstate")
                            s.sstate = values[i];

                        else if (field[i] == "stype")
                            s.stype = values[i];

                        else if (field[i] == "snetversion")
                            s.snetversion = values[i];

                        else if (field[i] == "smemeory")
                            s.smemeory = values[i];


                        else if (field[i] == "scpulimit")
                            s.scpulimit = values[i];


                        else if (field[i] == "smaxconnections")
                            s.smaxconnections = values[i];


                        else if (field[i] == "smaxbands")
                            s.smaxbands = values[i];


                        else if (field[i] == "spassword")
                            s.spassword = values[i];


                        else if (field[i] == "susername")
                            s.susername = values[i];


                        else if (field[i] == "slogpath")
                            s.slogpath = values[i];



                        else if (field[i] == "screatetime")
                            s.screatetime = values[i];


                        else if (field[i] == "sphysicalpath")
                            s.sphysicalpath = values[i];

                        else if (field[i] == "sbindings")
                            s.sbindings = values[i];

                        else if (field[i] == "sname")
                            s.sname = values[i];



                        NLogger.Info(field[i] + ":" + values[i]);

                    }
                    int errorCode = Data<Sites>.GetInstance().Add(insert_sql, s);


                }
            }

            // 获取数据库站点信息


            string sql = "  select * from sites where   1=1   ";
            Sites Sites = new Sites();
            var list = Data<Sites>.GetInstance().GetModelList(sql, Sites);




            return list;
        }

        #endregion



        /// <summary>
        /// 从数据库表中获取站点信息作为生成配置
        /// </summary>
        public static DataTable adoGetConfigSitesInfo()
        {
            /*
             * 获取数据库站点信息
             */
            //  string select_sql = "select sname,sbindings,sphysicalpath,sphpath,susername,spassword,smaxbands,smaxconnections,scpulimit,smemeory,shomepages,stype,snetversion from yroot_sites";		    //查询的SQL语句
            DataTable dt = null;// AccessHelper.ExecuteDataTable(select_sql, null);	   //执行查询操作,结果存放在dt中
            //AccessHelper.CloseConnection();
            return dt;
        }
        /// <summary>
        /// 将存在的站点保存到数据库表中
        /// </summary>
        public static List<Sites> adoFlushSites()
        {
            IISManager iismanager = new IISManager();
               
            List<string> sitesids = new List<string>();
            /*
            * 获取数据库存在的站点信息
            */
       

            List<string> ysids = new List<string>();


            string getinfo_sql = "select * from Sites ";

            List<Sites> list = new List<Sites>();
            Sites SqlInfo = new Sites();
            list = Data<Sites>.GetInstance().GetModelList(getinfo_sql, SqlInfo);



            foreach (var  sid in list)
            {
                ysids.Add(sid.sid.ToString());
            }  
            /*
            * 获取本地站点信息
            */ 
            List<string> sitelist = iismanager.getSiteInfo();
            if(sitelist!=null)
            {

           
            foreach (string siteinfo in sitelist)
            {

                string[] site = Regex.Split(siteinfo, "-@-");//独立站点信息
                sitesids.Add(site[0]);//本地站点列表
                if (!ysids.Contains(site[0]))
                {
                    try
                    {
                        /*
                       * 存储到数据库
                       */
                        string insert_sql = "insert into sites(sid,sname,sbindings,sphysicalpath,screatetime,slogpath,susername,spassword, smaxbands, smaxconnections, scpulimit, smemeory, snetversion, stype, sstate, sphpath, shomepages) values(@sid,@sname,@sbindings,@sphysicalpath,@screatetime,@slogpath,@susername,@spassword, @smaxbands, @smaxconnections, @scpulimit, @smemeory, @snetversion, @stype, @sstate, @sphpath, @shomepages)";



                      
                        string[] field = { "sid", "sname", "sbindings", "sphysicalpath", "screatetime", "slogpath", "susername", "spassword", "smaxbands", "smaxconnections", "scpulimit", "smemeory", "snetversion", "stype", "sstate", "sphpath", "shomepages" };
                        string[] values = site;
                    
                    

                        Sites s = new Sites();
                        for (int i = 0; i < values.Length; i++)
                        {
                            if (field[i] == "sid")
                                s.sid = values[i];



                            else if (field[i] == "shomepages")
                                s.shomepages = values[i];

                            else if (field[i] == "sphpath")
                                s.sphpath = values[i];

                            else if (field[i] == "sstate")
                                s.sstate = values[i];

                            else if (field[i] == "stype")
                                s.stype = values[i];

                            else if (field[i] == "snetversion")
                                s.snetversion = values[i];

                            else if (field[i] == "smemeory")
                                s.smemeory = values[i];


                            else if (field[i] == "scpulimit")
                                s.scpulimit = values[i];


                            else if (field[i] == "smaxconnections")
                                s.smaxconnections = values[i];


                            else if (field[i] == "smaxbands")
                                s.smaxbands = values[i];


                            else if (field[i] == "spassword")
                                s.spassword = values[i];


                            else if (field[i] == "susername")
                                s.susername = values[i];


                            else if (field[i] == "slogpath")
                                s.slogpath = values[i];



                            else if (field[i] == "screatetime")
                                s.screatetime = values[i];


                            else if (field[i] == "sphysicalpath")
                                s.sphysicalpath = values[i];

                            else if (field[i] == "sbindings")
                                s.sbindings = values[i];

                            else if (field[i] == "sname")
                                s.sname = values[i];



                            NLogger.Info(field[i] + ":" + values[i]);

                        }
                        int errorCode = Data<Sites>.GetInstance().Add(insert_sql, s);






                    }
                    catch (Exception ex)
                    {
                        NLogger.Error(ex.ToString());
                    }
                }
                else
                {
                    try
                    {
                        /*
                        * 更新到数据库
                        */
                      string update_sql = "update sites set sname=@sname, sbindings=@sbindings, sphysicalpath=@sphysicalpath, screatetime=@screatetime, slogpath=@slogpath, susername=@susername, spassword=@spassword, smaxbands=@smaxbands, smaxconnections=@smaxconnections, scpulimit=@scpulimit, smemeory=@smemeory, snetversion=@snetversion,stype=@stype, sstate=@sstate, sphpath=@sphpath, shomepages=@shomepages where sid=@sid";        //插入的SQL语句(带参数)
                                                                                                                                                                                                                                                                                                                                                                                                                                                
                      
                        string[] field2 = { "sname", "sbindings", "sphysicalpath", "screatetime", "slogpath", "susername", "spassword", "smaxbands", "smaxconnections", "scpulimit", "smemeory", "snetversion", "stype", "sstate", "sphpath", "shomepages", "sid" };
                        /*
                         * 处理字串
                         */
                        List<string> tmplist = site.ToList();
                        tmplist.Add(tmplist[0]);
                        tmplist.RemoveAt(0);
                        site = tmplist.ToArray();
                        string[] values2 = site;

                        Sites s = new Sites();
                        for (int i = 0; i < values2.Length; i++)
                        {
                            if (field2[i] == "sid")
                                s.sid = values2[i];



                            else if (field2[i] == "shomepages")
                                s.shomepages = values2[i];

                            else if (field2[i] == "sphpath")
                                s.sphpath = values2[i];

                            else if (field2[i] == "sstate")
                                s.sstate = values2[i];

                            else if (field2[i] == "stype")
                                s.stype = values2[i];

                            else if (field2[i] == "snetversion")
                                s.snetversion = values2[i];

                            else if (field2[i] == "smemeory")
                                s.smemeory = values2[i];


                            else if (field2[i] == "scpulimit")
                                s.scpulimit = values2[i];


                            else if (field2[i] == "smaxconnections")
                                s.smaxconnections = values2[i];


                            else if (field2[i] == "smaxbands")
                                s.smaxbands = values2[i];


                            else if (field2[i] == "spassword")
                                s.spassword = values2[i];


                            else if (field2[i] == "susername")
                                s.susername = values2[i];


                            else if (field2[i] == "slogpath")
                                s.slogpath = values2[i];



                            else if (field2[i] == "screatetime")
                                s.screatetime = values2[i];


                            else if (field2[i] == "sphysicalpath")
                                s.sphysicalpath = values2[i];

                            else if (field2[i] == "sbindings")
                                s.sbindings = values2[i];

                            else if (field2[i] == "sname")
                                s.sname = values2[i];



                            NLogger.Info(field2[i] + ":" + values2[i]);

                        }


                     
                        int errorCode = Data<Sites>.GetInstance().Update(update_sql, s);


                    }
                    catch (Exception ex)
                    {
                        NLogger.Error(ex.ToString());

                    }
                }
            }
            }
            /*
             *删除不存在的站点
             */

            if(list!=null)
            {

          
            foreach (var  sid in list)
            {
                try
                {
                    if (!sitesids.Contains(sid.sid.ToString()))
                    {

                        Sites s = new Sites();
                        string delete_sql = " sid=@sid";        //插入的SQL语句(带参数)
                         
                       

                        string[] field = { "sid" };
                        string[] values = { sid.sid.ToString() };

                        s.sid = sid.sid.ToString();
                        for (int i = 0; i < values.Length; i++)
                        {
                       
                        }
                        int errorCode = Data<Sites>.GetInstance().Delete("sites", delete_sql, s);

                      
                    }
                }
                catch (Exception ex)
                {
                    NLogger.Error(ex.ToString());

                }
            }
            }

            string sql = "  select * from sites where   1=1   ";
            Sites Sites = new Sites();
            return Data<Sites>.GetInstance().GetModelList(sql, Sites);




             

        }


          
        /// <summary>
        /// 将存在的站点保存到数据库表中
        /// </summary>
        public static void adoFlushFtpInfos()
        {
            IISManager iismanager = new IISManager();

            List<string> ftpsids = new List<string>();
            /*
            * 获取数据库存在的ftp信息
            */  
            string getinfo_sql = "select * from Ftpsite ";

            List<Ftpsite> list = new List<Ftpsite>();
            Ftpsite SqlInfo = new Ftpsite();
            list = Data<Ftpsite>.GetInstance().GetModelList(getinfo_sql, SqlInfo);
            

            List<string> ysids = new List<string>();
            foreach (var  sid in list)
            {
                ysids.Add(sid.Name.ToString());
            }

              

            /*
            * 获取本地站点信息
            */
            List<string> ftplist = iismanager.getFtpInfo();
            foreach (string ftpinfo in ftplist)
            {

                string[] ftp = Regex.Split(ftpinfo, "-@-");//独立站点信息
                ftpsids.Add(ftp[1]);//本地站点列表
                if (!ysids.Contains(ftp[1]))
                {
                    /*
                   * 存储到数据库
                   */

                     

                    string insert_sql = "insert into Ftpsite(Name,Pwd,OperPower,Path,CreTime,iisversion) values(@Name,@Pwd,@OperPower,@Path,@CreTime,@iisversion)";       //插入的SQL语句(带参数)
                    Ftpsite Ftpsite = new Ftpsite();

                  
                    string[] field = { "ftproot", "ftpname", "ftppass", "ftppath", "iisversion" };
                    string[] values = ftp;
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (field[i] == "ftproot")
                            Ftpsite.ftproot = values[i];
                        else
                            if (field[i] == "ftpname")
                            Ftpsite.Name = values[i];

                        else
                            if (field[i] == "ftppass")
                            Ftpsite.Pwd = values[i];

                        else
                            if (field[i] == "ftppath")
                            Ftpsite.Path = values[i];

                        else
                            if (field[i] == "iisversion")
                            Ftpsite.iisversion = values[i];

                     
                    }
                    Ftpsite.CreTime = DateTime.Now.ToString();
                    Ftpsite.OperPower = "未知";



                    Data<Ftpsite>.GetInstance().Add(insert_sql, Ftpsite);




                }
                else
                {
                    /*
                    * 更新到数据库
                    */
                    string update_sql = "update Ftpsite set ftproot=@ftproot, Pwd=@Pwd, Path=@Path, iisversion=@iisversion where Name=@Name ";        //插入的SQL语句(带参数)
                                                                                                                                                      ///   OleDbParameter[] para2 = new OleDbParameter[5];		//构造并绑定参数

                    string[] field2 = { "ftproot", "ftppass", "ftppath", "iisversion", "ftpname" };
                    /*
                     * 处理字串
                     */
                    List<string> tmplist = ftp.ToList();
                    tmplist.Add(tmplist[1]);
                    tmplist.RemoveAt(1);
                    ftp = tmplist.ToArray();
                    string[] values2 = ftp;
                    Ftpsite Ftpsite = new Ftpsite();
                    for (int i = 0; i < values2.Length; i++)
                    {
                        if (field2[i] == "ftproot")
                            Ftpsite.ftproot = values2[i];
                        else
                          if (field2[i] == "ftpname")
                            Ftpsite.Name = values2[i];

                        else
                          if (field2[i] == "ftppass")
                            Ftpsite.Pwd = values2[i];

                        else
                          if (field2[i] == "ftppath")
                            Ftpsite.Path = values2[i];

                        else
                          if (field2[i] == "iisversion")
                            Ftpsite.iisversion = values2[i];






                    }

                  


                    Data<Ftpsite>.GetInstance().Update(update_sql, Ftpsite);

                }
            }
            /*
             *删除不存在的站点
             */
            foreach (var sid in list)
            {
                if (!ftpsids.Contains(sid.Name.ToString()))
                {
                    string delete_sql = " Name=@Name";        //插入的SQL语句(带参数)
                                                                                       ///  OleDbParameter[] para = new OleDbParameter[1];		//构造并绑定参数

                    string[] field = { "ftpname" };
                    string[] values = { sid.Name.ToString() };
                    Ftpsite delSqlInfo = new Ftpsite();
                    for (int i = 0; i < values.Length; i++)
                    {
                        delSqlInfo.Name = values[i];
                      

                    }
                  
                    Data<Ftpsite>.GetInstance().Delete("Ftpsite", delete_sql, delSqlInfo);
                    
                }
            }
           
          
        }
     
        
          
        /// <summary>
        /// 将指定站点存储到数据库表
        /// </summary>
        public static int adoSaveNewSite(string newsitename)
        {
            int errorCode = ErrorCode.saveNewSiteOK;

            try
            {
                IISManager iismanager = new IISManager();

               
               // 获取本地站点信息
            
                string siteinfo = iismanager.getNewSiteInfo(newsitename);
                string[] site = Regex.Split(siteinfo, "-@-");
                /*
                * 存储到数据库
                */
              //  string insert_sql = "insert into yroot_sites(sid,sname,sbindings,sphysicalpath,screatetime,slogpath,susername,spassword, smaxbands, smaxconnections,scpulimit, smemeory,snetversion ,stype, sstate, sphpath, shomepages) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";        //插入的SQL语句(带参数)
           ///  //   OleDbParameter[] para = new OleDbParameter[17];		//构造并绑定参数
              //  string[] field = { "sid", "sname", "sbindings", "sphysicalpath", "screatetime", "slogpath", "susername", "spassword", "smaxbands", "smaxconnections", "scpulimit", "smemeory", "snetversion", "stype", "sstate", "sphpath", "shomepages" };
              //  string[] values = site;
             //   for (int i = 0; i < values.Length; i++)
              //  {
             ///  //     para[i] = new OleDbParameter(field[i], values[i]);
              //  }
                ///   AccessHelper.ExecuteNonQuery(insert_sql, para);
                //AccessHelper.CloseConnection();


                string insert_sql = "insert into sites(sid,sname,sbindings,sphysicalpath,screatetime,slogpath,susername,spassword, smaxbands, smaxconnections, scpulimit, smemeory, snetversion, stype, sstate, sphpath, shomepages) values(@sid,@sname,@sbindings,@sphysicalpath,@screatetime,@slogpath,@susername,@spassword, @smaxbands, @smaxconnections, @scpulimit, @smemeory, @snetversion, @stype, @sstate, @sphpath, @shomepages)";

                string[] field = { "sid", "sname", "sbindings", "sphysicalpath", "screatetime", "slogpath", "susername", "spassword", "smaxbands", "smaxconnections", "scpulimit", "smemeory", "snetversion", "stype", "sstate", "sphpath", "shomepages" };
                string[] values = site;
                Sites s = new Sites();
                for (int i = 0; i < values.Length; i++)
                {
                    if (field[i] == "sid")
                        s.sid = values[i];



                    else if (field[i] == "shomepages")
                        s.shomepages = values[i];

                    else if (field[i] == "sphpath")
                        s.sphpath = values[i];

                    else if (field[i] == "sstate")
                        s.sstate = values[i];

                    else if (field[i] == "stype")
                        s.stype = values[i];

                    else if (field[i] == "snetversion")
                        s.snetversion = values[i];

                    else if (field[i] == "smemeory")
                        s.smemeory = values[i];


                    else if (field[i] == "scpulimit")
                        s.scpulimit = values[i];


                    else if (field[i] == "smaxconnections")
                        s.smaxconnections = values[i];


                    else if (field[i] == "smaxbands")
                        s.smaxbands = values[i];


                    else if (field[i] == "spassword")
                        s.spassword = values[i];


                    else if (field[i] == "susername")
                        s.susername = values[i];


                    else if (field[i] == "slogpath")
                        s.slogpath = values[i];



                    else if (field[i] == "screatetime")
                        s.screatetime = values[i];


                    else if (field[i] == "sphysicalpath")
                        s.sphysicalpath = values[i];

                    else if (field[i] == "sbindings")
                        s.sbindings = values[i];

                    else if (field[i] == "sname")
                        s.sname = values[i];



                    NLogger.Info(field[i] + ":" + values[i]);

                }
                 Data<Sites>.GetInstance().Add(insert_sql, s);







            }
            catch (Exception ex)
            {
                NLogger.Error(ex.ToString());
                errorCode = ErrorCode.saveNewSiteFail;
            }

            return errorCode;

        }
        /// <summary>
        /// 将站点设置更新到数据库表
        /// </summary>
        public static int adoSaveNowSite(string newsitename)
        {
            int errorCode = ErrorCode.sqlExcOK;

            try
            {
                IISManager iismanager = new IISManager();

                /*
                * 获取本地站点信息
                */
                string siteinfo = iismanager.getNewSiteInfo(newsitename);
                string[] site = Regex.Split(siteinfo, "-@-");
                ///*
                //* 更新到数据库
                //*/
                //string update_sql = "update sites set sname=@, sbindings=?, sphysicalpath=?, screatetime=?, slogpath=?, susername=?, spassword=?, smaxbands=?, smaxconnections=?, scpulimit=?, smemeory=?, snetversion=?,stype=?, sstate=?, sphpath=?, shomepages=? where sid=?";    
                ////插入的SQL语句(带参数)
                //                                                                                                                                                                                                                                                                                 ///  OleDbParameter[] para2 = new OleDbParameter[17];		//构造并绑定参数

                //string[] field2 = { "sname", "sbindings", "sphysicalpath", "screatetime", "slogpath", "susername", "spassword", "smaxbands", "smaxconnections", "scpulimit", "smemeory", "snetversion", "stype", "sstate", "sphpath", "shomepages", "sid" };



                string update_sql = "update sites set sname=@sname, sbindings=@sbindings, sphysicalpath=@sphysicalpath, screatetime=@screatetime, slogpath=@slogpath, susername=@susername, spassword=@spassword, smaxbands=@smaxbands, smaxconnections=@smaxconnections, scpulimit=@scpulimit, smemeory=@smemeory, snetversion=@snetversion,stype=@stype, sstate=@sstate, sphpath=@sphpath, shomepages=@shomepages where sid=@sid";        //插入的SQL语句(带参数)


                string[] field2 = { "sname", "sbindings", "sphysicalpath", "screatetime", "slogpath", "susername", "spassword", "smaxbands", "smaxconnections", "scpulimit", "smemeory", "snetversion", "stype", "sstate", "sphpath", "shomepages", "sid" };
                /*
                 * 处理字串
                 */
                List<string> tmplist = site.ToList();
                tmplist.Add(tmplist[0]);
                tmplist.RemoveAt(0);
                site = tmplist.ToArray();
                string[] values2 = site;

                Sites s = new Sites();
                for (int i = 0; i < values2.Length; i++)
                {
                    if (field2[i] == "sid")
                        s.sid = values2[i];



                    else if (field2[i] == "shomepages")
                        s.shomepages = values2[i];

                    else if (field2[i] == "sphpath")
                        s.sphpath = values2[i];

                    else if (field2[i] == "sstate")
                        s.sstate = values2[i];

                    else if (field2[i] == "stype")
                        s.stype = values2[i];

                    else if (field2[i] == "snetversion")
                        s.snetversion = values2[i];

                    else if (field2[i] == "smemeory")
                        s.smemeory = values2[i];


                    else if (field2[i] == "scpulimit")
                        s.scpulimit = values2[i];


                    else if (field2[i] == "smaxconnections")
                        s.smaxconnections = values2[i];


                    else if (field2[i] == "smaxbands")
                        s.smaxbands = values2[i];


                    else if (field2[i] == "spassword")
                        s.spassword = values2[i];


                    else if (field2[i] == "susername")
                        s.susername = values2[i];


                    else if (field2[i] == "slogpath")
                        s.slogpath = values2[i];



                    else if (field2[i] == "screatetime")
                        s.screatetime = values2[i];


                    else if (field2[i] == "sphysicalpath")
                        s.sphysicalpath = values2[i];

                    else if (field2[i] == "sbindings")
                        s.sbindings = values2[i];

                    else if (field2[i] == "sname")
                        s.sname = values2[i];



                    NLogger.Info(field2[i] + ":" + values2[i]);

                }



                Data<Sites>.GetInstance().Update(update_sql, s);





                /*
                 * 处理字串
                 */
                //List<string> tmplist = site.ToList();
                //tmplist.Add(tmplist[0]);
                //tmplist.RemoveAt(0);
                //site = tmplist.ToArray();
                //string[] values2 = site;
                //for (int i = 0; i < values2.Length; i++)
                //{
                /////    para2[i] = new OleDbParameter(field2[i], values2[i]);
                //}
               /// AccessHelper.ExecuteNonQuery(update_sql, para2);
                //AccessHelper.CloseConnection();
            }
            catch (Exception ex)
            {
                NLogger.Error(ex.ToString());
                errorCode = ErrorCode.sqlExcFail;
            }

            return errorCode;

        }
        /// <summary>
        /// 删除数据库记录
        /// </summary>
        public static int adoDeleteSite(string deletesitename)
        {
            int errorCode = ErrorCode.sqlExcOK;
            try
            {
                string delete_sql = " sname=@sname ";
                
                Sites Sites = new Sites();
                Sites.sname = deletesitename;
                Data<Sites>.GetInstance().Delete("Sites", delete_sql, Sites);
                
            }
            catch (Exception ex)
            {
                NLogger.Error(ex.ToString());
                errorCode = ErrorCode.sqlExcFail;
            }
            return errorCode;
        }
        /// <summary>
        /// 执行简单的语句
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static object adoNormalExecute(string sql, string[] args, string[] field)
        {
            int errorCode = ErrorCode.sqlExcOK;

            try
            {
                if (args != null)
                {
                  ///  OleDbParameter[] para = new OleDbParameter[args.Length];		//构造并绑定参数
                    for (int i = 0; i < args.Length; i++)
                    {
                     ///   para[i] = new OleDbParameter(field[i], args[i]);
                    }
                    DataTable dt = null;// AccessHelper.ExecuteDataTable(sql, para);
                    //AccessHelper.CloseConnection();//关闭连接
                    return dt;
                }
                else
                {
                    DataTable dt = null;// AccessHelper.ExecuteDataTable(sql, null);	   //执行查询操作,结果存放在dt中
                    //AccessHelper.CloseConnection();//关闭连接
                    return dt;
                }
            }
            catch
            {
                errorCode = ErrorCode.sqlExcFail;
            }

            return errorCode;

        }
        /// <summary>
        /// 带返回值得查询
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static object adoNormalGetExecute(string sql, string[] args, string[] field)
        {
            int errorCode = ErrorCode.sqlExcOK;

            try
            {
                if (args != null)
                {
                 //   OleDbParameter[] para = new OleDbParameter[args.Length];		//构造并绑定参数
                    for (int i = 0; i < args.Length; i++)
                    {
                   //     para[i] = new OleDbParameter(field[i], args[i]);
                    }
                    DataTable dt = null;// AccessHelper.ExecuteDataTable(sql, para);
                    //AccessHelper.CloseConnection();//关闭连接
                    return dt;
                }
                else
                {
                    DataTable dt = null;// AccessHelper.ExecuteDataTable(sql, null);	   //执行查询操作,结果存放在dt中
                    //AccessHelper.CloseConnection();//关闭连接
                    return dt;
                }
            }
            catch
            {
                errorCode = ErrorCode.sqlExcFail;
            }

            return errorCode;

        }
    }
}
